package com.traffic.managent;

import java.io.IOException;

import javax.servlet.ServletException;

import com.traffic.managent.annotation.ControllerBind;
import com.traffic.managent.base.CxBaseController;
import com.traffic.managent.util.ImageCode;

@ControllerBind(controllerKey = "/front")
public class Home extends CxBaseController {

	public static final String PATH = "/home/";

	/**
	 * 登录
	 */
	public void login() {
		setAttr("pre_page", getPrePage());
		renderAuto("/login.html");
	}

	public void error() {
		java.util.Random random = new java.util.Random();// 定义随机类
		int result = random.nextInt(5);
		switch (result) {
		case 1: {
			render("/pages/error/i/3D404/birds.html");
			break;
		}
		case 2: {
			render("/pages/error/i/3D404/cat.html");
			break;
		}
		case 3: {
			render("/pages/error/i/3D404/dragon.html");
			break;
		}
		default: {
			render("/pages/error/i/3D404/fish.html");
			break;
		}
		}
	}

	/**
	 * 登出
	 */
	public void logout() {
		removeSessionUser();
		redirect("/home");
	}

	/**
	 * 生成注册码
	 */
	public void image_code() {
		try {
			new ImageCode().doGet(getRequest(), getResponse());
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		renderNull();
	}

}
